package com.study.mybatis.executor.statement;

import com.study.mybatis.executor.Executor;
import com.study.mybatis.mapping.MappedStatement;
import com.study.mybatis.session.ResultHandler;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

/**
 * @author yuantongqin
 * 2021/7/31
 **/
public class PreparedStatementHandler extends BaseStatementHandler {


    public PreparedStatementHandler(Executor executor, MappedStatement mappedStatement, Object parameterObject, ResultHandler resultHandler) {
        super(executor, mappedStatement, parameterObject, resultHandler);
    }

    @Override
    public <E> List<E> query(Statement statement) throws SQLException {
        return null;
    }

    @Override
    public <E> List<E> query(Statement statement, ResultHandler resultHandler) throws SQLException {
        PreparedStatement ps = (PreparedStatement) statement;
        ps.execute();
        return resultSetHandler.handleResultSets(ps);
    }

    @Override
    public void parameterize(Statement statement,Object parameter) throws SQLException {

        parameterHandler.setParameters((PreparedStatement) statement,parameter);
    }
}
